<!-- //测试渲染时间canvas是87438ms -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <canvas width="960" height="960"></canvas>
    <script src="d3.v4.min.js"></script>
    <script>
        const canvas = document.querySelector('canvas')
        const ctx = canvas.getContext("2d")
        const width = canvas.width
        height = canvas.height
        num = 1000000


        const nodes = d3.range(num).map(
            d=>{
                return {
                    x:Math.random()*width,
                    y:Math.random()*height
                }
            }
        )

        const t1 = new Date().getTime()


        // ctx.clearRect(0,0,width,height)
        // ctx.beginPath()
        nodes.forEach((d,i)=>{
            ctx.beginPath()//一定要放在里面，不然性能急剧下降
            // ctx.moveTo(d.x + 2, d.y);//这一句不能够缺少
            ctx.arc(d.x, d.y, 2, 0, 2 * Math.PI);
            ctx.fill()
            // console.log(i);
            // ctx.strokeStyle = "#fff";
            ctx.stroke();
        }
        )

        const t2 = new Date().getTime()

        console.log(`渲染时间是${t2-t1}ms`);


    </script>
</body>
</html>